package com.yanzu.module.system.dal.mysql.dict;

import com.yanzu.framework.mybatis.core.mapper.BaseMapperX;
import com.yanzu.module.system.dal.dataobject.dict.DeviceNumDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DeviceNumMapper extends BaseMapperX<DeviceNumDO> {


    @Delete("DELETE FROM systrm_device_num WHERE configuration_id=#{configurationId}")
    void deleteByTenantId(Long configurationId);

    /**
     * 根据类别查询租户所有设备数据
     * @param tenantId
     * @param type
     * @return
     */
    @Select("select count(1)\n" +
            "        from member_device_info\n" +
            "        where deleted = 0\n" +
            "          and type = #{type}\n" +
            "          and tenant_id = #{tenantId}")
    int getTenCount(@Param("tenantId") Long tenantId, @Param("type") Integer type);


    /**
     * 查询需要开启或者关闭的设备id
     * @param limitNum
     * @param order
     * @return
     */
    @Select(" SELECT\n" +
            "            device_id\n" +
            "        FROM\n" +
            "            ( SELECT * FROM member_device_info WHERE tenant_id = #{tenantId} AND deleted = '0' AND type = #{type} ORDER BY create_time ${order} ) a\n" +
            "            LIMIT #{limitNum}")
    List<Long> getDeviceId(@Param("limitNum") Integer limitNum,@Param("order")  String order,@Param("tenantId") Long tenantId,@Param("type") Integer type);


    /**
     * 修改设备是否有效
     * @param deviceIds
     * @return
     */
    @Update("UPDATE member_device_info SET is_enable = #{isEnable} WHERE device_id IN (${deviceIds})")
    int updateEnable(@Param("isEnable") Integer isEnable, @Param("deviceIds") String deviceIds);


}
